package com.mentaleye.biz.impl;

import com.mentaleye.bean.CurriculumBean;
import com.mentaleye.biz.CurriculumBiz;
import com.mentaleye.dal.model.CurriculumExample;
import com.mentaleye.service.CurriculumService;
import com.mentaleye.util.CommonPage;
import com.mentaleye.util.CommonResult;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CurriculumBizImpl implements CurriculumBiz {
    @Autowired
	private CurriculumService curriculumService;
	private static Logger logger = Logger.getLogger(CurriculumBizImpl.class);

	public List<CurriculumBean> queryCurriculum(Integer curriculumTempNo) {
	 try {
			Map<String,Object> map=new HashMap<String, Object>();
			map.put("readyRelate", curriculumTempNo);
			return curriculumService.queryCurriculum(map);
		}catch (Exception e){
		 logger.error("根据模版查询课程异常",e);
			return  null;
		}

	}
	
	public List<CurriculumBean> queryCurriculumByExample(CurriculumExample example){
		return curriculumService.queryCurriculum(example);
	}

	public CurriculumBean getCurriculumByNo(Integer curriculumNo) {
		try {
		return curriculumService.getCurriculumByNo(curriculumNo);
		}catch (Exception e){
			logger.error("根据课程编号查询课程异常",e);
			return  null;
		}
	}

	public void queryCurriculumByPage(CommonPage commonPage) {
		try {
		List<CurriculumBean> data=curriculumService.queryCurriculumByPage(commonPage.pageToMap());
		commonPage.setPageData(data);
		}catch (Exception e){
			logger.error("查询课程分页异常",e);
		}

	}

	public CommonResult editCurriculum(CurriculumBean curriculum) {
		CommonResult result = new CommonResult();
		boolean add;
		boolean success=true;
			add =curriculum.getCurriculumNo()==null;
			try {
				success=curriculumService.editCurriculum(curriculum, add);
			} catch (Exception e) {
				logger.error("编辑课程异常",e);
				success=false;
			}

		result.setIsSuccess(success);
		return result;
	}

	public CommonResult deleteCurriculum(List<Integer> ids) {
		try {
		return new CommonResult(curriculumService.deleteCurriculum(ids));
		} catch (Exception e) {
			logger.error("删除课程异常",e);
			return new CommonResult();
		}
	}
}